package com.x19i.framework.config;

import com.esotericsoftware.kryo.serializers.TimeSerializers;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ser.std.NumberSerializers;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;

import java.time.format.DateTimeFormatter;
import java.util.TimeZone;

import static com.x19i.common.utils.DateUtils.*;

/**
 * @author Su.Xiaosong
 * @date 2024-08-16
 * @since 1.0
 */
@Configuration
public class JacksonConfigure {
    @Bean
    public MappingJackson2HttpMessageConverter  jackson2ObjectMapperBuilder(){
        Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder()
                .featuresToDisable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)
                .timeZone(TimeZone.getTimeZone("GMT+8:00"))
                .serializers(new LocalTimeSerializer(DTF_HH_MI_SS))
                .serializers(new LocalDateSerializer(DTF_YYYY_MM_DD))
                .serializers(new LocalDateTimeSerializer(DTF_YYYY_MM_DD__HH_MI_SS))
                .serializers(new NumberSerializers.LongSerializer(String.class))
                .serializationInclusion(JsonInclude.Include.NON_NULL);
        return new MappingJackson2HttpMessageConverter(builder.build());
    }


}
